import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;


public class ReadData {
	
public static HashMap<Integer,User> getMoviesEvaluated(){
	
		HashMap<Integer,User> users= new HashMap<>(0);
		String csvFile = "train.csv";
		BufferedReader br = null;
		String line = "";
		String csvSplitBy = ";";
		

		try {
			br = new BufferedReader(new FileReader(csvFile));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			while ((line = br.readLine()) != null) {
 
			        
				String[] data = line.split(csvSplitBy);
				if(users.containsKey((Integer.parseInt(data[1])))==false || users.get(Integer.parseInt(data[1]))==null){			//is user already added to hashmap
					User newuser=new User(Integer.parseInt(data[1]));
					newuser.evaluatedMovies.add(new Evaluation(Integer.parseInt(data[2]) , data[3]));
					users.put(Integer.parseInt(data[1]), newuser);
				}
				else{									//add user to hashmap
					users.get((Integer.parseInt(data[1]))).evaluatedMovies.add(new Evaluation(Integer.parseInt(data[2]) , data[3]));
				}
 
			}
			br.close();
		} catch (NumberFormatException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return users;
	}
	
	
	
	public static HashMap<Integer,User> getMoviesToBeEvaluated(HashMap<Integer,User> users){
		
		String csvFile = "task.csv";
		BufferedReader br = null;
		String line = "";
		String csvSplitBy = ";";
		

		try {
			br = new BufferedReader(new FileReader(csvFile));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			while ((line = br.readLine()) != null) {			        
				String[] data = line.split(csvSplitBy);
				users.get((Integer.parseInt(data[1]))).notEvaluatedMovies.add(new Evaluation(Integer.parseInt(data[2]) , data[3]));
 
			}
			br.close();
		} catch (NumberFormatException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return users;
	}
	
public static HashMap<Integer,Movie> getMoviesWithFeatures(){
	
	HashMap<Integer,Movie> movies= new HashMap<>(0);
	String csvFile = "data.csv";
	BufferedReader br = null;
	String line = "";
	String csvSplitBy = ";";
	

	try {
		br = new BufferedReader(new FileReader(csvFile));
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	try {
		while ((line = br.readLine()) != null) {			        
			String[] data = line.split(csvSplitBy);
			if(movies.containsKey((Integer.parseInt(data[1])))==false || movies.get(Integer.parseInt(data[1]))==null){			//is user already added to hashmap
				Movie newmovie=new Movie(Integer.parseInt(data[1]));
				newmovie.features.add(new Feature(Integer.parseInt(data[2]) , data[3]));
				movies.put(Integer.parseInt(data[1]), newmovie);
			}
			else{									//add user to hashmap
				movies.get((Integer.parseInt(data[1]))).features.add(new Feature(Integer.parseInt(data[2]) , data[3]));
			}
		}
		br.close();
	} catch (NumberFormatException | IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return movies;
}

	
	

}
